<?php
  require('includes/application_top.php');

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_DEFAULT);

  
?>
<?php
	$typeIndex = $_GET['type'];
	$sql_getProduct = "select distinct p.products_id, p.products_image, p.products_tax_class_id, pd.products_name, 
if(s.status, s.specials_new_products_price, p.products_price) as products_price from ". TABLE_PRODUCTS ." p 
left join ". TABLE_SPECIALS ." s on p.products_id = s.products_id
 INNER JOIN           ". TABLE_PRODUCTS_ATTRIBUTES ." ON p.products_id = products_attributes.products_id INNER JOIN
                      ". TABLE_PRODUCTS_DESCRIPTION ." pd ON p.products_id = pd.products_id INNER JOIN
                      ". TABLE_PRODUCTS_OPTIONS ." ON products_attributes.options_id = products_options.products_options_id INNER JOIN
                      ". TABLE_PRODUCTS_OPTIONS_VALUES ." ON products_attributes.options_values_id = products_options_values.products_options_values_id CROSS JOIN
                      ". TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS .", ". TABLE_PRODUCTS_TO_CATEGORIES ." p2c, ". TABLE_CATEGORIES ." c 
WHERE     products_options_values.products_options_values_name = '".$typeIndex."'
	AND products_options.products_options_name = 'Sale'
	and p.products_id = p2c.products_id 
	and p2c.categories_id = c.categories_id 
	and p.products_status = '1' 
	and p.products_id = pd.products_id 
	and pd.language_id = '" . (int)$languages_id . "'";

?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">       
 <link rel="stylesheet" type="text/css" href="<?php echo $theme_file_path; ?>">

</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<div class="container">

            <!-- header //-->
            <?php require(DIR_WS_INCLUDES . 'header.php'); ?>
            <!-- header_eof //-->

            <!-- navigation //-->
            <?php require(DIR_WS_INCLUDES . 'navigation.php'); ?>
    <div id="content-header">
        <?php echo $breadcrumb->trail(' &raquo; '); ?>
    </div>
   <table width="100%">
   <tr>
<!-- body_text //-->
    <td width="100%" valign="top">
    <?php
    $listing_split = new splitPageResults($sql_getProduct, MAX_DISPLAY_SEARCH_RESULTS, 'p.products_id');

$products_query = tep_db_query($listing_split->sql_query);

  
$i = 1;
$k = 0;
$str = $typeIndex ;
if ($listing_split->number_of_rows > 0)
    echo '<p class="marginT10">'. mb_convert_case($str, MB_CASE_UPPER, "utf-8") .'. '. $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS) . '</p>';

echo '<div class="clear marginT10">';
if (tep_db_num_rows($products_query) > 0) {
    while ($products = tep_db_fetch_array($products_query)) {
        if ($k % 5 == 0 && $k > 0) {
            echo '</div><div class="clear marginT10">';
            $i = 1;
        }

        if ($i == 1)
            $css = 'item1';
        else if ($i == 2)
            $css = 'item2';
        else if ($i == 3)
            $css = 'item3';
        else if ($i == 4)
            $css = 'item4';
        else
            $css = 'item5';

        echo '<div class="' . $css . '">
						<table border="0" cellpadding="0" cellspacing="0" width="100%">
							<tr><td style="padding-top: 10px;"></td></tr>
							<tr>
								<td align="center"><a href="' . tep_href_link('product_info.php', 'products_id=' . $products['products_id']) . '"> <img src="images/' . $products['products_image'] . '" alt="" border="0px"/></a></td>
							</tr>
							<tr><td style="padding-top: 10px;"></td></tr>
							<tr>
								<td><strong><a href="' . tep_href_link('product_info.php', 'products_id=' . $products['products_id']) . '">' . $products['products_name'] . '</a></strong></td>
							</tr>
							<tr>
								<td>' . substr($products['products_description'], 0, 50) . '...</td>
							</tr>
							<tr>
								<td><div id="price"><p>' . $currencies->display_price($products['products_price'], tep_get_tax_rate($products['products_tax_class_id'])) . ' <a href="' . tep_href_link('index.php', 'cPath=' . $current_category_id . '&action=buy_now&products_id=' . $products['products_id']) . '"><img src="pub/images/icon_basket.gif" border="0"  align="center"/></a></p></div></td>
							</tr>
						</table>

					</div>';
        $i++;
        $k++;
    }
}
else {
    echo '<div style="padding: 1px 0px 20px 0px;">'. TEXT_DISPLAY_NO_PRODUCT .'</div>';
}
echo '</div>';

if ($listing_split->number_of_rows > 0) {
    echo '<div class=" clear"></div>
			            <table width="100%" border="0" cellpadding="0" cellspacing="0" class="marginT10">
				 	<tr><td colspan="2" style="height: 10px;"></td></tr>
					<tr>
						<td align="left">' . $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS) . '</td>
						<td align="right">' . TEXT_RESULT_PAGE . ' ' . $listing_split->display_links(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))) . '</td>
					</tr></table>';
}
?></td></tr></table>
<!-- body_text_eof //-->
			<div class="seperator2"></div>
            <!-- content eof //-->
    		<?php require(DIR_WS_INCLUDES . 'contact_info.php'); ?>
            <!-- footer //-->
            <?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
            <!-- footer_eof //-->
        </div>
    </body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>